
package com.huatie.gateway;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;

/**
 * SpringBoot Gateway网关主启动类
 * 功能说明：
 * 1. 集成Nacos服务发现
 * 2. 配置路由规则访问rocketmq服务
 */
@SpringBootApplication
public class SpringbootGatewayApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringbootGatewayApplication.class, args);
    }

    /**
     * 配置路由规则
     * @param builder 路由构建器
     * @return 路由定位器
     */
    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                // 路由到rocketmq服务
                .route("rocketmq_route", r -> r.path("/rocketmq/**")
                        .filters(f -> f.stripPrefix(1)) // 去掉前缀
                        .uri("lb://springboot-rocketmq")) // 使用服务发现
                .build();
    }
}
